package com.zzy.servicebase.exceptionhandler;

import com.zzy.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author KAZU
 * @Date 2023/1/8 9:27
 * @Version 1.0
 */
@SuppressWarnings({"all"})
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
	
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public R error(Exception e) {
		e.printStackTrace();
		return R.error().message(String.valueOf(e));
	}
	
	@ExceptionHandler(ArithmeticException.class)
	public R error(ArithmeticException e) {
		e.printStackTrace();
		return R.error().message("ArithmeticException(Create breakpoint)...");
	}
	
	@ExceptionHandler(GuliException.class)
	public R error(GuliException e) {
		log.error(e.getMessage());
		e.printStackTrace();
		return R.error().code(e.getCode()).message(e.getMsg());
	}
	
}
